package top.zyx.rpc.loadbalance.loadbalancer;

import top.zyx.rpc.entity.RpcRequest;
import top.zyx.rpc.loadbalance.AbstractLoadBalance;

import java.util.List;

public class RoundRobinLoadBalancer extends AbstractLoadBalance {
    private int index = 0;
    @Override
    protected String doSelect(List<String> serviceAddresses, RpcRequest rpcRequest) {
        if(index >= serviceAddresses.size()) {
            index %= serviceAddresses.size();
        }
        return serviceAddresses.get(index++);
    }
}
